package com.fx.device;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fx.device.repository.DeviceMaintenanceRepository;
import com.fx.device.vo.device.DeviceMaintenanceRecord;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@SpringBootTest
public class Part1_Deployment {
    @Autowired
    private DeviceMaintenanceRepository deviceMaintenanceRepository;


    @Test
    public void testCommonInsert() {
        //初始化Employee对象
        DeviceMaintenanceRecord deviceMaintenanceRecord = new DeviceMaintenanceRecord();
        deviceMaintenanceRecord.setImageAfterMaintenanceId(3);
        deviceMaintenanceRecord.setMaintenancePlanNo("测试12312313123");
        deviceMaintenanceRecord.setMaintenancePerson("华安公寓测试2");
        deviceMaintenanceRecord.setMaintenanceTime(1123L);
        deviceMaintenanceRecord.setImageBeforeMaintenanceId(31);
        deviceMaintenanceRecord.setMaintenanceResult("通过");
        deviceMaintenanceRecord.setRemark("这是测试数据第二条");


        //insert方法在插入时，会根据实体类的每个属性进行非空判断，只有非空的属性对应的字段才会出现到SQL语句中
        Integer result = deviceMaintenanceRepository.insert(deviceMaintenanceRecord);
        System.out.println("result: " + result);
//        //insertAllColumn方法在插入时，不管属性是否非空， 属性所对应的字段都会出现到SQL语句中.
//        Integer result1 = deviceMaintenanceRecordRepository.insertAllColumn(deviceMaintenanceRecord);
//        System.out.println("result: " + result1 );
//        //获取当前数据在数据库中的主键值
//        Integer key = deviceMaintenanceRecord.getId();
//        System.out.println("key:" + key );

    }


    @Test
    public void testSelectmain() {
        //DeviceMaintenanceRecord deviceMaintenanceRecord  = new DeviceMaintenanceRecord();
        List<Integer> integerList = new ArrayList<>();
        integerList.add(1);
        integerList.add(2);
        integerList.add(3);

        List<DeviceMaintenanceRecord> deviceMaintenanceRecords = deviceMaintenanceRepository.selectBatchIds(integerList);
        System.out.println(deviceMaintenanceRecords);


    }

    @Test
    public void testDelSelect() {
        //DeviceMaintenanceRecord deviceMaintenanceRecord  = new DeviceMaintenanceRecord();


        List<DeviceMaintenanceRecord> deviceMaintenanceRecords = deviceMaintenanceRepository.selectList(null);
        System.out.println(deviceMaintenanceRecords);


    }


    @Test
    void selectByPageMap() {


        QueryWrapper<DeviceMaintenanceRecord> wrapper = new QueryWrapper<>();
        wrapper.likeRight("maintenancePerson", "测试");
        IPage<DeviceMaintenanceRecord> page = new Page<>(1, 2);
        IPage<Map<String, Object>> devicePage = deviceMaintenanceRepository.selectMapsPage(page, wrapper);
        System.out.println(devicePage.getPages());
        System.out.println(devicePage.getTotal());
        List<Map<String, Object>> users = devicePage.getRecords();
        users.forEach(System.out::println);
    }

    @Test
    void queryorcloum(){

        QueryWrapper<DeviceMaintenanceRecord> queryWrapper = new QueryWrapper();

        queryWrapper.likeRight("maintenancePlanNo", "测试数据").or()
                .likeRight("maintenanceTime", null)
                .or().likeRight("maintenanceResult", null).or()
                .likeRight("maintenancePlanNo", null).orderByDesc("id");



        List<DeviceMaintenanceRecord> list = deviceMaintenanceRepository.selectList(queryWrapper);
        list.forEach(System.out::println);



    }








    }












